#define fexit(s) { fprintf( stderr, "%s\n", s ); exit(1); }
#include <stdio.h>
#include <stdlib.h>
#include "../../jerasure-2.h"

int main( int argc, char** argv )
{
	JER_Matrix *matrix;
	int r = atoi( argv[1] );
	int c = atoi( argv[2] );
	int w = atoi( argv[3] );
	JER_Matrix *matrix2;
	int i, j, fsize;
	int c1, c2;
	int prod;

	matrix = new JER_Matrix( r, c, w );
	if( matrix == NULL )
		fexit( "Matrix could not be allocated." );
	srand48(c);
	fsize = 1 << w;
	for( i = 0; i < r * c; i++ )
		matrix->Elts[i/c][i%c] = lrand48() % fsize;
	matrix->Print();
	for( i = 0; i < w; i++ )
	{
		c1 = lrand48() % c;
		c2 = lrand48() % c;
		prod = lrand48() % w;
		fprintf( stdout, "c1 = %d\nc2 = %d\nprod = %d\n", c1, c2, prod );

		for( j = 0; j < r; j++ )
			matrix->Elts[j][c1] ^= galois_single_multiply( 
					matrix->Elts[j][c2], prod, w );
		matrix->Print();
		fprintf( stdout, "----------\n" );
	}

	return 0;
}
